//
//  ProductImagesTableViewCell.m
//  MyNewProject
//
//  Created by ZhangYuan on 2019/1/28.
//  Copyright © 2019年 sun. All rights reserved.
//

#import "ProductImagesTableViewCell.h"

@implementation ProductImagesTableViewCell
- (nonnull instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.webView];
    }
    return self;
}

- (void)setContentString:(NSString *)contentString
{
    _contentString = contentString;
    [self.webView ba_web_loadHTMLString:contentString];
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.webView.frame = self.bounds;
}
- (WKWebView *)webView
{
    if (!_webView)
    {
        _webView = [WKWebView new];
        _webView.ba_web_isAutoHeight = YES;
        //  添加 WKWebView 的代理，注意：用此方法添加代理
        BAKit_WeakSelf
        [_webView ba_web_initWithDelegate:weak_self.webView uIDelegate:weak_self.webView];
        
        _webView.backgroundColor = [UIColor whiteColor];
        _webView.userInteractionEnabled = false;
        
        self.webView.ba_web_getCurrentHeightBlock = ^(CGFloat currentHeight) {
            
            BAKit_StrongSelf
            self.cell_height = currentHeight;
            if (self.WebLoadFinish)
            {
                self.WebLoadFinish(self.cell_height);
            };
        };
        [self.contentView addSubview:_webView];
    }
    return _webView;
}
@end
